package com.example.mapp;

import com.example.entity.EmergencyRescue;
import com.example.ext.entity.ExtEmergencyRescue;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by youkun on 2017/10/3.
 */
@Mapper
public interface EmergencyRescueMapp {

    @Select(" select a.*, b.party_name as rescuePartyName from emergency_rescue a " +
            "left join party b on a.rescue_party_id=b.id where a.id=#{id}")
    ExtEmergencyRescue findById(String id) throws Exception;

    @Select(" select a.*, b.party_name as rescuePartyName from emergency_rescue a " +
            "left join party b on a.rescue_party_id=b.id where a.elevator_id=#{elevatorId} order by id desc")
    List<ExtEmergencyRescue> findList(ExtEmergencyRescue extEmergencyRescue) throws Exception;

    @Delete("delete from emergency_rescue where id=#{id}")
    int deleteById(String id)throws Exception;

    @Insert("insert into emergency_rescue " +
            "(elevator_id, elevator_num,received_time,arrived_time,rescue_end_time,pic_url,accident_reason,rescue_party_id,rescue_party_name," +
            "no_casualties,minor_wound_num,injured_num,death_num,protective,protective_oth," +
            "rescue_user_name1,rescue_user_name2,rescue_user_sign_url,rescue_user_sign_url2,signed_time,security_admin_sign_url,sured_time) " +
            "value " +
            "(#{elevatorId},#{elevatorNum}, #{receivedTime},#{arrivedTime}, #{rescueEndTime},#{picUrl},#{accidentReason},#{rescuePartyId},#{rescuePartyName}," +
            "#{noCasualties},#{minorWoundNum},#{injuredNum},#{deathNum},#{protective},#{protectiveOth}" +
            ",#{rescueUserName1},#{rescueUserName2},#{rescueUserSignUrl},#{rescueUserSignUrl2},#{signedTime},#{securityAdminSignUrl},#{suredTime})")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    int add(EmergencyRescue emergencyRescue) throws Exception;

    @Update("update emergency_rescue set elevator_id=#{elevatorId} where id=#{id}")
    int update(EmergencyRescue emergencyRescue) throws Exception;


}
